﻿<html>
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<script type="text/javascript" src="jquery/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="fancyapps-fancyBox/source/jquery.fancybox.js?v=2.1.5"></script>
		<link rel="stylesheet" type="text/css" href="fancyapps-fancyBox/source/jquery.fancybox.css?v=2.1.5" media="screen" />
	</head>
	<body>
		<style type="text/css">
			.gallery-line {
				width: 36%;
				margin-left: auto;
				margin-right: auto;
				text-align: center;
				clear: left;
			}
			.gallery-line font {
				cursor: pointer;
				text-decoration: underline;
				color: #0099ff;
			}
			.gallery-line img { cursor: pointer; }
			.gallery-line font:hover { text-decoration: none; }
			.gallery-line .CurrentPage {
				cursor: default;
				text-decoration: none;
				color: #383838;
			}
			.gallery-cell {
				width: 150px;
				float: left;
				padding: 5px;
			}
			.upload-block {
				text-align: center;
				clear: left;
			}
			.upload-button {
				opacity: 0.8;
				cursor: pointer;
			}
			.upload-button:hover { opacity: 1; }
			.ajax-cn { display: none }
		</style>
		<script type="text/javascript">
		$(document).ready(function() {
			/*
			 *  Simple image gallery. Uses default settings
			 */

			$('.fancybox').fancybox();

			/*
			 *  Different effects
			 */

			// Change title type, overlay closing speed
			$(".fancybox-effects-a").fancybox({
				helpers: {
					title : {
						type : 'outside'
					},
					overlay : {
						speedOut : 0
					}
				}
			});

			// Disable opening and closing animations, change title type
			$(".fancybox-effects-b").fancybox({
				openEffect  : 'none',
				closeEffect	: 'none',

				helpers : {
					title : {
						type : 'over'
					}
				}
			});

			// Set custom style, close if clicked, change title type and overlay color
			$(".fancybox-effects-c").fancybox({
				wrapCSS    : 'fancybox-custom',
				closeClick : true,

				openEffect : 'none',

				helpers : {
					title : {
						type : 'inside'
					},
					overlay : {
						css : {
							'background' : 'rgba(238,238,238,0.85)'
						}
					}
				}
			});

			// Remove padding, set opening and closing animations, close if clicked and disable overlay
			$(".fancybox-effects-d").fancybox({
				padding: 0,

				openEffect : 'elastic',
				openSpeed  : 150,

				closeEffect : 'elastic',
				closeSpeed  : 150,

				closeClick : true,

				helpers : {
					overlay : null
				}
			});

			/*
			 *  Button helper. Disable animations, hide close button, change title type and content
			 */

			$('.fancybox-buttons').fancybox({
				openEffect  : 'none',
				closeEffect : 'none',

				prevEffect : 'none',
				nextEffect : 'none',

				closeBtn  : false,

				helpers : {
					title : {
						type : 'inside'
					},
					buttons	: {}
				},

				afterLoad : function() {
					this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
				}
			});


			/*
			 *  Thumbnail helper. Disable animations, hide close button, arrows and slide to next gallery item if clicked
			 */

			$('.fancybox-thumbs').fancybox({
				prevEffect : 'none',
				nextEffect : 'none',

				closeBtn  : false,
				arrows    : false,
				nextClick : true,

				helpers : {
					thumbs : {
						width  : 50,
						height : 50
					}
				}
			});

			/*
			 *  Media helper. Group items, disable animations, hide arrows, enable media and button helpers.
			*/
			$('.fancybox-media')
				.attr('rel', 'media-gallery')
				.fancybox({
					openEffect : 'none',
					closeEffect : 'none',
					prevEffect : 'none',
					nextEffect : 'none',

					arrows : false,
					helpers : {
						media : {},
						buttons : {}
					}
				});

			/*
			 *  Open manually
			 */

			$("#fancybox-manual-a").click(function() {
				$.fancybox.open('1_b.jpg');
			});

			$("#fancybox-manual-b").click(function() {
				$.fancybox.open({
					href : 'iframe.html',
					type : 'iframe',
					padding : 5
				});
			});

			$("#fancybox-manual-c").click(function() {
				$.fancybox.open([
					{
						href : '1_b.jpg',
						title : 'My title'
					}, {
						href : '2_b.jpg',
						title : '2nd title'
					}, {
						href : '3_b.jpg'
					}
				], {
					helpers : {
						thumbs : {
							width: 75,
							height: 50
						}
					}
				});
			});


		});
	</script>
		<script type="text/javascript">
			$(document).ready(function(){
				$('.upload-button').bind('click', function(){
					$('.upload-form').submit();
				});
				GalleryGen(1);
			});
			function GalleryGen(p) {
				$('.gallery-subject').html('<div class="gallery-line"><br/><img src="ajax-loader.gif" /><br/></div>');
				$('.ajax-cn').load('index.php', {page: p}, function(){
					var data = $('.ajax-cn').text();
					var GALLERY = '';
					if( data == 0 ) {
						var GALLERY = '<br/>Нет изображений<br/>';
					} else {
						var GALLERY_LINE = '';
						var cell_counter = 0;
						var data_el = data.split('^');
						for( var I = 1; I < data_el.length; I += 2) {
							if( cell_counter == 3 ) {
								GALLERY +=
								'<div class="gallery-line">' + "\r\n" +
								GALLERY_LINE +
								'</div>' + "\r\n";
								GALLERY_LINE = '';
								cell_counter = 0;
							}
							if( cell_counter < 3 ) {
								GALLERY_LINE += '	<div class="gallery-cell"><a class="fancybox" href="upload/'+data_el[I+1]+'" data-fancybox-group="gallery"><img title="'+data_el[I]+'" src="upload/thumb/'+data_el[I+1]+'" /></a></div>'+"\r\n";
								cell_counter ++;
							}
						}
						if( cell_counter <= 3 ) {
							GALLERY +=
							'<div class="gallery-line">' + "\r\n" +
							GALLERY_LINE +
							'</div>' + "\r\n";
						}
					}
					$('.gallery-subject').html(GALLERY);
					if( data_el[0] > 12 ) {
						var GALLERY_NAVIGATION = '';
						var all_pages = parseInt(data_el[0]/12)+1;
						for( var page_number = 1; page_number <= all_pages; page_number++ ) {
							if( page_number != p ) {
								GALLERY_NAVIGATION += '<font onclick="GalleryGen('+page_number+');">'+page_number+'</font>&nbsp;';
							} else {
								GALLERY_NAVIGATION += '<font class="CurrentPage">'+page_number+'<font>&nbsp;';
							}
						}
						var previous_page_button = p > 1 ? '<img src="previous-page-button.gif" onclick="GalleryGen('+(p-1)+');" />&nbsp;' : '' ;
						var next_page_button = p < all_pages ? '<img src="next-page-button.gif" onclick="GalleryGen('+(p+1)+');">' : '';
						var ALL_HTML_NAVIGATION = 
						'<div class="gallery-line"><br/><hr/></div>' +
						'<div class="gallery-line">' +
							previous_page_button +
							GALLERY_NAVIGATION +
							next_page_button +
						'</div>' +
						'<div class="gallery-line"><hr/></div>';
						$('.gallery-navigation').html(ALL_HTML_NAVIGATION);
					}
				});
			}
		</script>
		<div class="gallery-subject"></div>
		<div class="gallery-navigation"></div>
		<div class="upload-block">
		<form class="upload-form" action="index.php" method="post" enctype="multipart/form-data">
			Ваш файл<input type="file" name="uploaded-image" />, JPG, PNG<br/><br/>
			Описание (TITLE) <input type="text" name="des" size="20" maxlength="30" /><br/><br/>
			<image class="upload-button" src="add-new-image-button.gif" />
		</form>
		</div>
		<div class="ajax-cn"></div>
	</body>
</html>